<!-- 设备参数 -->
<template>
  <div class="dashboard-editor-container" style="min-width:1150px">
    <el-row style="background: #fff; padding: 16px 16px 0; margin-bottom: 32px">
      <div class="btn topSubmitBtn" style="width:880px">
      <el-button type="primary" @click="submit()">保存设置</el-button>
    </div>
      <div class="input-item"> 
        <el-form :model="deviceform"  label-width="220px">
          <div class="parameType-wrap">
            <div class="parameType">
              <!-- <div class="title">装置维护相关参数</div> -->
              <el-col :xs="24" :sm="24" :lg="24">
                <el-form-item label="终端代理心跳间隔:">
                  <el-input v-model="deviceform.agent_hand_shake_interval" oninput="value=value.replace(/[^0-9]/g,'')" maxlength="6"><span slot="append">秒</span></el-input>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="24" :lg="24">
                <el-form-item label="终端代理心跳超时次数:">
                  <el-input v-model="deviceform.lost_hand_shake_times" oninput="value=value.replace(/[^0-9]/g,'')" maxlength="6"></el-input>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="24" :lg="24">
                <el-form-item label="终端代理网络连接检测间隔:">
                  <el-input v-model="deviceform.check_agent_net_status_interval" oninput="value=value.replace(/[^0-9]/g,'')" maxlength="6"><span slot="append">秒</span></el-input>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="24" :lg="24">
                <el-form-item label="终端代理定时更新参数间隔:">
                  <el-input v-model="deviceform.refresh_agent_param_interval" oninput="value=value.replace(/[^0-9]/g,'')" maxlength="6"><span slot="append">秒</span></el-input>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="24" :lg="24">
                <el-form-item label="终端代理自动升级检测间隔:">
                  <el-input v-model="deviceform.agent_auto_upgrade_interval" oninput="value=value.replace(/[^0-9]/g,'')" maxlength="6"><span slot="append">秒</span></el-input>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="24" :lg="24">
                <el-form-item label="屏幕录像质量:">
                  <el-select v-model="deviceform.agent_auto_capture_screen_quality" style="width:100%;">
                    <el-option label="高清" value=100></el-option>
                    <el-option label="普通" value=75></el-option>
                    <el-option label="一般" value=50></el-option>
                    <el-option label="压缩" value=25></el-option>
                  </el-select>
                  <span style="color:#aaa">
                    （质量越高占用空间越大，建议使用高清）
                  </span>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="24" :lg="24">
                <el-form-item label="屏幕录像间隔:">
                  <el-input v-model="deviceform.agent_auto_capture_screen_interval" oninput="value=value.replace(/[^0-9]/g,'')" maxlength="6"><span slot="append">秒</span></el-input>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="24" :lg="24">
                <el-form-item label="客户端托盘显示控制:">
                  <el-radio v-model="deviceform.agent_show_trayicon" :label="1">显示</el-radio>
                  <el-radio v-model="deviceform.agent_show_trayicon" :label="0">隐藏</el-radio>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="24" :lg="24">
                <el-form-item label="客户端托盘显示控制退出菜单:">
                  <el-radio v-model="deviceform.agent_show_trayicon_exit" :label="1">显示</el-radio>
                  <el-radio v-model="deviceform.agent_show_trayicon_exit" :label="0">隐藏</el-radio>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="24" :lg="24">
                <el-form-item label="外贸数据打开模式:">
                  <el-radio v-model="deviceform.agent_guard_clipboard_email" :label="1">嵌入方式（推荐）</el-radio>
                  <el-radio v-model="deviceform.agent_guard_clipboard_email" :label="0">开放模式</el-radio>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="24" :lg="24">
                <el-form-item label="客户端托盘退出密码:">
                  <el-input v-model="deviceform.agent_trayicon_exit_pwd" maxlength="36"></el-input>
                  <!-- <span style="color:#aaa">
                    （空表示不需要密码）
                  </span> -->
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="24" :lg="24">
                <el-form-item label="客户端托盘提示内容:">
                  <el-input v-model="deviceform.agent_trayicon_tip" maxlength="36"></el-input>
                </el-form-item>
              </el-col>
            </div>
          </div>
        </el-form>
      </div>
        
    </el-row>
  </div>
</template>

<script>
import Cookies from 'js-cookie'
import { connrequest } from "@/api/firstPage"
export default {
  data() {
    return {
      deviceform:{
      },
      oldData:[],
    }
  },
  //生命周期 - 创建完成（访问当前this实例）
  created() {
    this.getData()
  },
  //生命周期 - 挂载完成（访问DOM元素）
  mounted() {},
  methods: {
    async getData(){
      const res = await connrequest('GetParamThreshhold')
      const res1 = await connrequest('GetParamLogCfg')
      let obj = {}
      res.Data = res.Data || []
      res.Data.map( item  => {
        obj[item.Name] = item.Value
      })
      this.oldData = res.Data
      obj.reset_keep_run_seconds = obj.reset_keep_run_seconds === '0' ? '不控制' : obj.reset_keep_run_seconds
      this.deviceform = {...obj, ...res1.Data}
    },
    async submit(){
      this.deviceform.reset_keep_run_seconds = this.deviceform.reset_keep_run_seconds === '不控制' ? '0' : this.deviceform.reset_keep_run_seconds
      let number = /^\d+$/
      let character64 = /^.{1,64}$/
      if (!number.test(this.deviceform.reset_keep_run_seconds)) {
        this.$message.error("连续运行多长时间自动重启设备只能填数字");
        return false;
      }
      if (!number.test(this.deviceform.write_watch_dog_interval)) {
        this.$message.error("进程自检喂狗周期只能填数字");
        return false;
      }
      if (!number.test(this.deviceform.default_log_days)) {
        this.$message.error("日志默认显示天数只能填数字");
        return false;
      }
      if (!character64.test(this.deviceform.default_log_days)) {
        this.$message.error("有线网口名称不能超过63位字符");
        return false;
      }
      if (!number.test(this.deviceform.report_new_url_interval)) {
        this.$message.error("上报新访问URL间隔只能填数字");
        return false;
      }
      if (!number.test(this.deviceform.same_proxy_interval)) {
        this.$message.error("同一个网址访问归并周期只能填数字");
        return false;
      }
      if (!number.test(this.deviceform.real_stream_log_keep_seconds)) {
        this.$message.error("实时流量缓存周期只能填数字");
        return false;
      }
      if (!number.test(this.deviceform.sync_email_notify_interval)) {
        this.$message.error("邮件通知状态更新间隔只能填数字");
        return false;
      }
      if (!number.test(this.deviceform.report_email_accounts_interval)) {
        this.$message.error("上送共享邮件账号间隔只能填数字");
        return false;
      }
      if (!number.test(this.deviceform.sync_email_share_accounts_interval)) {
        this.$message.error("同步共享邮件账号间隔只能填数字");
        return false;
      }
      if (!number.test(this.deviceform.inner_refresh_param_interval)) {
        this.$message.error("授权参数自动更新周期只能填数字");
        return false;
      }
      if (!number.test(this.deviceform.report_status_interval)) {
        this.$message.error("上送设备状态信息间隔只能填数字");
        return false;
      }
      if (!number.test(this.deviceform.report_stream_sum_log_interval)) {
        this.$message.error("上送设备流量统计间隔只能填数字");
        return false;
      }
      if (!number.test(this.deviceform.LogSaveDays)) {
        this.$message.error("日志储存天数只能填数字");
        return false;
      }
      if (this.deviceform.agent_trayicon_exit_pwd === '') {
        this.$message.error("客户端托盘退出密码不能为空");
        return false;
      }
      
      this.oldData = this.oldData.map(item => {
        for (const key in this.deviceform) {
          if(item.Name === key){
            item.Value = this.deviceform[key]
          }
        }
        return item
      })
      const data = {
        Data: this.oldData
      }
      const res = await connrequest('SetParamThreshhold', data)
      const data1 = {
        Data:{
          AutoDelHours: this.deviceform.AutoDelHours * 1,
          LogSaveDays: this.deviceform.LogSaveDays * 1
        }
      }
      await connrequest('SetParamLogCfg', data1)
      if(res.Status.StatusCode === 0) {
        this.$message.success('保存成功')
        Cookies.set('DefaultLogDays', this.deviceform.default_log_days || 3)
        Cookies.set('DefaultPageLength', this.deviceform.page_length || 10)
        this.getData()
      }
    }
  }
}
</script>
<style lang="scss" scoped>
/* @import url(); 引入css类 */
  .parameType-wrap{
    display:flex;
    flex-wrap: wrap;
  }
  ::v-deep.input-item{
    width: 1100px;
    margin-top: 10px;
    .parameType{
      border: 1px solid #eceff5;
      border-radius: 3px;
      width: 530px;
      padding: 10px;
      margin: 10px 20px 10px 0px;
      box-shadow: 0 0 10px #eceff5;
      .title{
        border-bottom: 1px solid #eceff5;
        padding-bottom : 10px;
      }
    }
    .el-form-item{
      margin-bottom: 6px;
    }
    .el-input-group__append, .el-input-group__prepend{
      width: 60px;
      padding: 0;
      text-align: center;
    }
  }
  .title{
    margin-bottom: 20px;
  }
  ::v-deep.el-form-item{
    label{
      font-weight: 500;
    }
  }
</style>